﻿using System.Windows.Forms;
using System;

namespace WordQuiz
{
    public partial class AddWordForm : Form
    {
        private WordRepository wordRepository = new WordRepository();

        public AddWordForm()
        {
            InitializeComponent();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            string english = textBoxEnglish.Text.Trim();
            string chinese = textBoxChinese.Text.Trim();
            if (string.IsNullOrEmpty(english) || string.IsNullOrEmpty(chinese))
            {
                MessageBox.Show("英文和中文词义不能为空。");
                return;
            }
            try
            {
                wordRepository.AddWord(english, chinese);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加单词失败：" + ex.Message);
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
